//
//  SEGDoorRollingGateView.m
//  Commom
//
//  Created by Clavis on 2020/8/5.
//

#import "SEGDoorRollingGateView.h"
#import <ReactiveObjC/ReactiveObjC.h>

@implementation SEGDoorRollingGateView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self customUI];
    }
    return self;
}

- (void)customUI {
    self.backgroundColor = [UIColor.blackColor colorWithAlphaComponent:0.5];
    
    //白色背景视图
    CGFloat buttonHeight = 44.0;
    UIView *contentView = [[UIView alloc] init];
    contentView.backgroundColor = kColor_W;
    [self addSubview:contentView];
    [contentView mas_makeConstraints:^(MASConstraintMaker* make) {
        make.left.right.bottom.mas_equalTo(0);
        make.height.mas_equalTo(buttonHeight*3+LYSafeAreaBottom());
    }];
    
    UIButton *dismissButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:dismissButton];
    [dismissButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.mas_equalTo(0);
        make.bottom.equalTo(contentView.mas_top);
    }];
    [[dismissButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        [self removeFromSuperview];
    }];
    
    // 动作类型：1-开(默认);2-关;3-停
    UIButton *openButton = ({
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setTitle:@"开门" forState:UIControlStateNormal];
        [button setTitleColor:kColor_1 forState:UIControlStateNormal];
        button.titleLabel.font = kFont_16;
        [contentView addSubview:button];
        button;
    });
    [openButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.mas_equalTo(0);
        make.height.mas_equalTo(buttonHeight);
    }];
    [[openButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        if (self.buttonClickBlock) {
            self.buttonClickBlock(1);
        }
    }];
    
    UIButton *endButton = ({
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setTitle:@"停止" forState:UIControlStateNormal];
        [button setTitleColor:kColor_1 forState:UIControlStateNormal];
        button.titleLabel.font = kFont_16;
        [contentView addSubview:button];
        button;
    });
    [endButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(buttonHeight);
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(buttonHeight);
    }];
    [[endButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        if (self.buttonClickBlock) {
            self.buttonClickBlock(3);
        }
    }];
    
    UIButton *closeButton = ({
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setTitle:@"关门" forState:UIControlStateNormal];
        [button setTitleColor:kColor_1 forState:UIControlStateNormal];
        button.titleLabel.font = kFont_16;
        [contentView addSubview:button];
        button;
    });
    [closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(buttonHeight*2);
        make.left.right.bottom.mas_equalTo(0);
    }];
    [[closeButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        if (self.buttonClickBlock) {
            self.buttonClickBlock(2);
        }
    }];
    
    UIView *line1 = [[UIView alloc] init];
    line1.backgroundColor = kColor_L2;
    [contentView addSubview:line1];
    [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(buttonHeight);
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(0.5);
    }];
    
    UIView *line2 = [[UIView alloc] init];
    line2.backgroundColor = kColor_L2;
    [contentView addSubview:line2];
    [line2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(buttonHeight*2);
        make.left.right.mas_equalTo(0);
        make.height.mas_equalTo(0.5);
    }];
}

@end
